﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WSAP;

namespace CouplingBeamStiff
{
    /// <summary>
    /// 壳单元
    /// </summary>
    class Element: Rectangular
    {
        /// <summary>
        /// 单元编号
        /// </summary>
        public int Index { get; set; }

        /// <summary>
        /// 节点坐标J
        /// </summary>
        private Node NodeJ { get; set; }

        /// <summary>
        /// 节点坐标K
        /// </summary>
        private Node NodeK { get; set; }

        /// <summary>
        /// 节点坐标L
        /// </summary>
        private Node NodeL { get; set; }

        /// <summary>
        /// 是否为梁单元
        /// </summary>
        private bool IsBeam
        {
            get
            {
                return this.NodeK == null;
            }
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="nodeI"></param>
        /// <param name="material"></param>
        /// <param name="nodeJ"></param>
        /// <param name="nodeK"></param>
        /// <param name="nodeL"></param>
        public Element(double width,double height, double x, double y, Material material, bool isBeam)
            :base(width, height, x, y, material)
        {
            this.NodeJ = new Node(x + this.Width, y);
            //梁单元不构造NodeK NodeL
            if (isBeam) return;
            this.NodeK = new Node(x + this.Width, y + this.Height);
            this.NodeL = new Node(x, y + this.Height);
        }

        /// <summary>
        /// 获取单元的所有节点
        /// </summary>
        /// <returns></returns>
        public List<Node> GetNodelist()
        {
            return this.IsBeam ?
                new List<Node> { this.NodeI, this.NodeJ } :
            new List<Node> { this.NodeI, this.NodeJ, this.NodeK, this.NodeL };
        }

        /// <summary>
        /// 为模型添加壳单元
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool AddElement(WModelNet model)
        {
            if (this.IsBeam)
                return model.AddRectConcreteBeam(this.NodeI.Index, this.NodeJ.Index, NodeJ.X - NodeI.X, this.Height)
                    != null;
            else return model.AddShell(this.NodeI.Index, this.NodeJ.Index, this.NodeK.Index, this.NodeL.Index, GlobalVar.Thickness) != null;
        }
    }
}
